package com.msdp.service.impl;

import com.msdp.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService {

    private static final String MSG_SUBJECT = "验证码";
    private static final String MSG_FROM = "2605335101@qq.com";

    @Autowired
    private JavaMailSender mailSender;

    public void sendVerificationCode(String to, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(MSG_FROM); // 发送方邮箱
        message.setTo(to); // 接收方邮箱
        message.setSubject(MSG_SUBJECT); // 邮件主题
        message.setText("【商铺点评】:您的验证码为 " + code + "，如非本人操作，请忽略本邮件！"); // 邮件内容

        mailSender.send(message);
    }
}
